import Vue from 'vue'
import VueRouter from 'vue-router'
import { qqgwcqd } from "network/api.js";
Vue.use(VueRouter)


const VueRouterPush =VueRouter.prototype.push
VueRouter.prototype.push = function push (to) {
  return VueRouterPush.call(this, to).catch(err => err)
}
const home=()=>import('views/home/home.vue')
const car=()=>import('views/gouwuche/car.vue')
const me=()=>import('views/wode/me.vue')
const delet=()=>import('views/xiangqingy/delet.vue')
const login=()=>import('views/login/login.vue')
const orderdd=()=>import('views/orderdd/orderdd.vue')
const shouhuodizhi=()=>import('views/shouhuodizhi/shouhuodizhi.vue')
const xinzengdizhi=()=>import('views/xinzengdizhi/xinzengdizhi.vue')
const dingdanxq=()=>import('views/dingdanxq/dingdanxq.vue')
const fukuanchenggong=()=>import('views/fukuanchenggong/fukuanchenggong.vue')
const wodedingdan=()=>import('views/wodedingdan/wodedingdan.vue')
const wodeshouc=()=>import('views/wodeshouc/wodeshouc.vue')
const usersetting=()=>import('views/usersetting/usersetting.vue')
const xiugaidrmima=()=>import('views/usersetting/xiugaidrmima.vue')
const xiugainic=()=>import('views/usersetting/xiugainic.vue')
const xiugaitoux=()=>import('views/usersetting/xiugaitoux.vue')
const xiugaizhifmima=()=>import('views/usersetting/xiugaizhifmima.vue')
const sreach=()=>import('views/sreach/sreach.vue')
const dingweichengshi=()=>import('views/dingweichengshi/dingweichengshi.vue')
const routes = [
  {
    path: '/',
    redirect:'/home'
  },
  {
    path: '/dingweichengshi',
    component: dingweichengshi,
    name: 'dingweichengshi',
   
  },
  {
    path: '/sreach',
    component: sreach,
    name: 'sreach',
   
  },
  {
    path: '/xiugaidrmima',
    component: xiugaidrmima,
    name: 'xiugaidrmima',
    meta: {
      isLogin: true,
    }
  },
  {
    path: '/xiugainic',
    component: xiugainic,
    name: 'xiugainic',
    meta: {
      isLogin: true,
    }
  },
  {
    path: '/xiugaitoux',
    component: xiugaitoux,
    name: 'xiugaitoux',
    meta: {
      isLogin: true,
    }
  },
  {
    path: '/xiugaizhifmima',
    component: xiugaizhifmima,
    name: 'xiugaizhifmima',
    meta: {
      isLogin: true,
    }
  },
  {
    path: '/usersetting',
    component: usersetting,
    name: 'usersetting',
    meta: {
      isLogin: true,
    }
  },
  {
    path: '/wodeshouc',
    component: wodeshouc,
    name: 'wodeshouc',
    meta: {
      isLogin: true,
    }
  },
  {
    path: '/wodedingdan',
    component: wodedingdan,
    name: 'wodedingdan',
    meta: {
      isLogin: true,
    }
  },
  {
    path: '/fukuanchenggong',
    component: fukuanchenggong,
    name: 'fukuanchenggong',
    meta: {
      isLogin: true,
    }
  },
  {
    path:'/dingdanxq',
    component:dingdanxq,
    name:'dingdanxq',
    meta: {
      isLogin: true,
    }
  },
  {
    path:'/xinzengdizhi',
    component:xinzengdizhi,
    name:'xinzengdizhi',
    meta: {
      isLogin: true,
    }
  },
  {
    path:'/shouhuodizhi',
    component:shouhuodizhi,
    name:'shouhuodizhi',
    meta: {
      isLogin: true,
    }
  },
  {
    path:'/orderdd',
    component:orderdd,
    name:'orderdd',
    meta: {
      isLogin: true,
    }
  },
  {
    path:'/login',
    component:login,
    name:'login',
    
  },
  {
    path:'/home',
    component:home,
    name:'home',
    meta:{
      navbarkz:true
    }
  },
  {
    path:'/car',
    component:car,
    name:'car',
    meta:{
      isLogin: true,
      
    }
  },
  {
    path:'/me',
    component:me,
    name:'me',
    meta:{
      navbarkz:true,
      
    },
  },
  {
    path:'/delet',
    component:delet,
    name:'delet'
  }
  
]

const router = new VueRouter({
  mode: 'history',
  routes
})
router.beforeEach((to, from, next) => {
  console.log(to)
  if(to.meta.isLogin){
    //需要判断是否已经登录
    if(sessionStorage.getItem("token")){
      //已经登陆
      
      next()
    }else{
      next("/login")
    }
  }else{
    next()
  }
 
})




export default router
